package com.czk.tx.dao.impl;

import com.czk.jdbctemplate.entity.Count;
import com.czk.tx.dao.RepeableDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/1/6 16:58
 */
@Service
public class RepeableDaoImpl implements RepeableDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Count> select() {
        List<Count> list = jdbcTemplate.query("select * from count", new BeanPropertyRowMapper<>(Count.class));
        return list;
    }

    @Override
    public void update(Integer id) {
        String sql = "update count set money=money+? where id =?";
        jdbcTemplate.update(sql, 10, id);
    }
}
